package com.example.jmeter.entity;

import com.example.jmeter.enums.JmeterCommand;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: spring-agent
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2023-04-19 13:46
 **/
@Data
@NoArgsConstructor
public class ThreadGroup {

    private String name;

    // 循环次数
    private Integer loops;
    // 并发线程
    private Integer threads;

    // 时间间隔
    private Integer ramp_time;

    private String JParamLoops;

    private String JParamThreads;

    private List<HTTPSampler> httpSamplers = new ArrayList<>(8);

    public ThreadGroup(String name, Integer loops, Integer threads) {
        this.name = name;
        this.loops = loops;
        this.threads = threads;
        this.ramp_time = 1;
    }

    public ThreadGroup(String name, Integer loops, Integer threads, Integer ramp_time) {
        this.name = name;
        this.loops = loops;
        this.threads = threads;
        this.ramp_time = ramp_time;
    }

    public void addHttpSampler(HTTPSampler ... httpSamplers) {
        this.httpSamplers.addAll(Arrays.asList(httpSamplers));
    }

    public String getJParamLoops() {
        return JmeterCommand.getJmeterParam("loops", this.loops == null ? "10" : this.loops.toString());
    }

    public String getJParamThreads() {
        return JmeterCommand.getJmeterParam("threads", this.threads == null ? "10" : this.threads.toString());
    }
}
